<%inherit file="base.html"/>

<%def name="head()">
<script src="/static/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="/static/js/bootstrap-datetimepicker.min.css">
   <script>
    $(document).ready(function(){
        $("#query_begin_time").datetimepicker({format: 'yyyy-mm-dd hh:ii:ss',autoclose: true,todayBtn: true});
        $("#query_end_time").datetimepicker({format: 'yyyy-mm-dd hh:ii:ss',autoclose: true,todayBtn: true});
    });
    function do_submit(){
        $("#query_form").attr("action", "/admin/customer/billing");
        $("#query_form").submit();
    }
    function do_export(){
        $("#query_form").attr("action", "/admin/customer/billing/export");
        $("#query_form").submit();
        setTimeout(function(){$("#query_form").attr("action", "/admin/customer/billing");}, 0);
    }
   </script>
</%def>

<%def name="body()">
<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-rmb"></i>
            <h3 class="box-title">用户计费查询</h3>
        </div>
            <div class="box-body">
            <div class="container">
        <form id="query_form" class="form-horizontal form-well" role="form" action="/admin/customer/billing" method="post">
            ${xsrf_form_html()}           
            <div class="form-group">
                <label for="node_id" class="col-md-2 control-label">区域</label>
                <div class="col-md-3">
                    <select id="node_id" name="node_id" class="form-control" >
                    <option value=""></option>
                        % for node in node_list:
                          <option value="${node.id}"  ${str(node.id)==node_id and "selected" or ""}>${node.node_desc}</option>
                        % endfor
                    </select>
                </div>  
                <label for="account_number" class="col-md-2 control-label">上网账号</label>
                <div class="col-md-3">
                    <input type="text" id="account_number" name="account_number" value="${account_number or ''}" class="form-control">
                </div>
            </div>   
            <div class="form-group">
                <label for="query_begin_time" class="col-md-2 control-label">开始时间</label>

                <div class="col-md-3">
                    <input type="text" id="query_begin_time" name="query_begin_time" value="${query_begin_time or ''}" class="form-control form_datetime"  >
                </div>
                 <label for="query_end_time" class="col-md-2 control-label">结束时间</label>
                <div class="col-md-3">
                    <input type="text" id="query_end_time" name="query_end_time" value="${query_end_time or ''}"  class="form-control form_datetime">
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-offset-5 col-md-7">
                    <button type="submit" onclick="do_submit();" class="btn btn-primary">查询</button>
                    % if permit.match(current_user.username, '/admin/customer/billing/export'):
                    <a href="javascript:do_export();" class="btn btn-md btn-default"><span class="glyphicon glyphicon-arrow-down"></span>导出计费信息</a>
                    % endif
                </div>
            </div>
        </form>


        <table class="table table-hover">
            <thead>
            <tr>
                <th>账号</th>
                <th>会话编号</th>
                <th>开始时间</th>
                <th>会话时长</th>
                <th>已扣时长</th>
                <th>已扣流量</th>
                <th>应扣费用</th>
                <th>实扣费用</th>
                <th>剩余余额</th>
                <th>剩余时长</th>
                <th>剩余流量</th>
                <th>扣费时间</th>
            </tr>
            </thead>
            <tbody>
            % for bill,_,_ in page_data.result:
            <tr>
                <td>${bill.account_number}</td>
                <td>${bill.acct_session_id}</td>
                <td>${bill.acct_start_time}</td>
                <td>${utils.fmt_second(bill.acct_session_time)}</td>
                <td>${utils.fmt_second(bill.acct_times)}</td>
                <td>${utils.kb2mb(bill.acct_flows)}M</td>
                <td>${utils.fen2yuan(bill.acct_fee)}</td>
                <td>${utils.fen2yuan(bill.actual_fee)}</td>
                <td>${utils.fen2yuan(bill.balance)}</td>
                <td>${utils.sec2hour(bill.time_length)}</td>
                <td>${utils.kb2mb(bill.flow_length)}</td>
                <td>${bill.create_time}</td>
            </tr>
            % endfor
            </tbody>
        </table>

        ${page_data.render(form_id="query_form")}
    </div>
</div>
</div>
</section>

</%def>
